package com.lambda;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

public class TestBigDecimal {

	public static void main(String[] args) {
		List<BigClass> bcs = new ArrayList<>();
		BigClass one = BigClass.builder().code("11").value(new BigDecimal("100")).build();
		bcs.add(one);
		BigClass two = BigClass.builder().code("22").value(null).build();
		bcs.add(two);
		BigClass three = BigClass.builder().code("33").value(new BigDecimal("100")).build();
		bcs.add(three);
		System.out.println(bcs.stream().map(e->e.getValue() == null ? BigDecimal.ZERO : e.getValue()).reduce(BigDecimal.ZERO, BigDecimal::add));
		System.out.println(bcs.stream().map(BigClass::getValue).reduce(BigDecimal.ZERO, BigDecimal::add));
	}
	
	@Data
	@NoArgsConstructor
	@AllArgsConstructor
	@Builder
	static class BigClass {
		private String code;
		private BigDecimal value;
	}
	
}
